package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Message;
import com.itheima.service.MessageService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Reference
    private MessageService messageService;

    @RequestMapping("/savaMessage")
    public Result savaMessage(@RequestBody Map<String,String> map){

        try {
            return messageService.savaMessage(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"留言失败");
        }

    }

    /**
     * 查询所有的留言数据
     * @return
     */
    @GetMapping("/findAllMessages")
    public Result findAllMessages(){
        try {
            List<Map<String,Object>> messageList=messageService.findAllMessages();
            return new Result(true,"查询成功",messageList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询失败");
        }
    }
}
